
        import javax.swing.*;
        import java.awt.*;
        import java.awt.event.ActionEvent;
        import java.awt.event.ActionListener;
public class Transfer extends JPanel implements ActionListener {
    private JButton backBtn;
    private JButton sure;
    private Atmtest frame;
    private double money;
    private JTextField zhuanzhang;
    private User user1;
    private boolean a=false;
    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);

    }

    public Transfer(Atmtest frame){
        this.frame = frame;
        this.setLayout(null);
        this.setOpaque(false);

        zhuanzhang = new JTextField();
        zhuanzhang.setBounds(180, 500, 200, 30);
        this.add(zhuanzhang);

        sure = new JButton(Util.getIcon("/img/buttonSure.jpg"));
        sure.setBounds(900, 400, 100, 50);
        this.add(sure);
        sure.addActionListener(this);

        backBtn = new JButton(Util.getIcon("/img/buttonOff.jpg"));
        backBtn.setBounds(900, 330, 100, 50);
        this.add(backBtn);
        backBtn.addActionListener(this);

    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if(backBtn == e.getSource()){
            frame.switchPanel("menu");
        }
        if (sure == e.getSource()){
            if (!a){
                seek();

                zhuanzhang.setText("");
                return;
            }else {
                transferMoney();
                JOptionPane.showMessageDialog(this, "你的余额"+frame.getUser().getBalance()+""+user1.getId()+"的余额"+user1.getBalance());
            }
        }
    }

    public  void seek(){
        for (int j = 0; j <frame.getUsers().size(); j++) {
            if (zhuanzhang.getText().equals(frame.getUsers().get(j).getId())) {
                user1=frame.getUsers().get(j);
                a=true;
                return;
            }
        }
        JOptionPane.showMessageDialog(this, "未找到"+zhuanzhang.getText());

    }

    public void transferMoney(){
        money -= Integer.parseInt(zhuanzhang.getText());
        double money2 = user1.getBalance();
        money2 +=Integer.parseInt(zhuanzhang.getText());
        frame.getUser().setBalance(money);
       user1.setBalance(money2);
    }

    public void setMoney() {
        this.money = frame.getUsers().get(frame.getID()).getBalance();
    }
}